package com.my.shetuan.Interceptor;

import com.my.shetuan.controller.utils.SYSTENET;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class HandlerIntercpetor implements HandlerInterceptor{
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //判断是否登录，是否存在值
        HttpSession session = request.getSession();
        Object loginUser = session.getAttribute("loginUser");
        if (loginUser != null){
            return true;
        }else {
            //拦截
            request.setAttribute(SYSTENET.MSG,"请先登录");
            request.getRequestDispatcher("/").forward(request,response);
            return false;
        }
    }
}
